package com.example.teamtribe.common;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.teamtribe.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IconTextView extends FrameLayout {

    @BindView(R.id.iv_image)
    ImageView ivIcon;
    @BindView(R.id.tv_name)
    TextView tvName;

    public IconTextView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.item_club_detail, this, true);
        ButterKnife.bind(this, this);
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.IconTextView);
        if (attributes != null) {
            ivIcon.setImageResource(attributes.getResourceId(R.styleable.IconTextView_ITV_icon, R.drawable.ic_light));
            tvName.setText(attributes.getText(R.styleable.IconTextView_ITV_text));
            tvName.setTextColor(attributes.getColor(R.styleable.IconTextView_ITV_textColor, Color.BLACK));
            attributes.recycle();
        }
    }

    public void setIcon(@DrawableRes int resId) {
        ivIcon.setImageResource(resId);
    }

    public void setText(CharSequence text) {
        tvName.setText(text);
    }
}
